package cn.lirenyi.user.controller;

import cn.lirenyi.basic.exception.BusinessException;
import cn.lirenyi.basic.util.AjaxResult;
import cn.lirenyi.user.service.IVerifyCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {

    @Autowired
    private IVerifyCodeService iVerifyCodeService;

    @PostMapping("/sendSmsCode")
    public AjaxResult sendSmsCode(@RequestBody Map<String,String> map){
        try {
            // 获取phone属性
            // String phone = map.get("phone");
            // 用于区分是绑定业务还是注册业务
            // String type = map.get("type");
            // 把属性值传入业务层去校验
            iVerifyCodeService.sendSmsCode(map);
            return AjaxResult.me();
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("系统繁忙请稍后再试");
        }
    }

}
